<?php 
require 'init.php';
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">
    <title>【9.5新】 LV/路易威登 女士 BREA中号玫红漆皮手提斜挎包</title>
    <!-- Bootstrap core CSS -->
    <link href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <!-- Custom styles for this template -->
<style>
    #time{margin: 20px 0;}
   .timeout{
      display: inline-block;
      width: 72px;
      height: 30px;
      color:white;
      line-height: 30px;
      text-align: center;
      font-size: 12px;
      font-weight: 700;
      background: url(//gtms02.alicdn.com/tps/i2/TB1sIuvGXXXXXaKXVXXcUqb4XXX-72-279.png) 0px -64px no-repeat transparent;  
   } 
   #timeout{display: inline-block;line-height: 30px;margin-left:15px;}
</style>
</head>

<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">Project name</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            <form class="navbar-form navbar-right">
                <div class="form-group">
                    <input type="text" placeholder="Email" class="form-control">
                </div>
                <div class="form-group">
                    <input type="password" placeholder="Password" class="form-control">
                </div>
                <button type="submit" class="btn btn-success">Sign in</button>
            </form>
        </div><!--/.navbar-collapse -->
    </div>
</nav>

<div class="container">
    <!-- Example row of columns -->
    <div class="row" style="margin-top:50px;">
        <div class="col-md-5">
            <h3>LV/路易威登 </h3>
            <img id="goods" src="https://img.alicdn.com/bao/uploaded/i3/TB1KCyZIpXXXXa_XVXXXxMG_FXX_400x400.jpg">
        </div>
        <div class="col-md-6">
            <h4>【9.5新】 LV/路易威登 女士 BREA中号玫红漆皮手提斜挎包</h4>
            <h3>当前价 ¥ 5,000 </h3>
            <div id="time">
                <span class="timeout">抢购倒计时</span>
                <span id="timeout">距结束 
                    <span id="hh">0</span>时
                    <span id="mm">0</span>分
                    <span id="ss">0</span>秒
                </span>
            </div>
            <p>
                <input type="hidden" id="goods_id" name="goods_id" value="<?php echo $data['id']; ?>">
                <button type="button" class="btn btn-danger" disabled="disabled" id="buy">立即抢购</button>
            </p>
        </div>
    </div>


</div>


<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="//cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
<script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script>
var oTimer = null;
$(function(){
    oTimer = setInterval("timer(timeEnd)",1000);
    $("#buy").click(function(){
        $.post("add_queue.php",{"goods_id":$("#goods_id").val()},function(result){
            console.log(result)
            if(result.status){
                    console.log(result);
                    var oTimer = setInterval(function(){
                        $.post("goods_status.php",{key:result.data.key}, function(result){
                            console.log(result);
                        },'json');
                    },4000);
            }else{
                consle.log(result.message);
            }
        },'json');
    });
})
function timeEnd(){
    $("#buy").attr("disabled",false);
}
function timer(fn) {
    var endTime = "<?php echo date('Y-m-d H:i:s', $endTime); ?>";
    var ts = (new Date(endTime)) - (new Date());//计算剩余的毫秒数

    var dd = parseInt(ts / 1000 / 60 / 60 / 24, 10);//计算剩余的天数
    var hh = parseInt(ts / 1000 / 60 / 60 % 24, 10);//计算剩余的小时数
    var mm = parseInt(ts / 1000 / 60 % 60, 10);//计算剩余的分钟数
    var ss = parseInt(ts / 1000 % 60, 10);//计算剩余的秒数
    var ms = parseInt(ts % 1000, 10);
    dd = checkTime(dd);
    hh = checkTime(hh);
    mm = checkTime(mm);
    ss = checkTime(ss);
    var D = function(id){ return document.getElementById(id); }
    D("hh").innerHTML = hh;
    D("mm").innerHTML = mm;
    D("ss").innerHTML = ss;
    console.log();
    if(ts <= 0){
        fn && fn.call();
        clearInterval(oTimer);
    }
}
function checkTime(i) {
   if (i < 10) {  
       i = "0" + i;  
    }  
   return i;  
}    
</script>
</body>
</html>
